package com.ruoyi.web.controller.system;
//订单相关
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.AppOrder;
import com.ruoyi.system.service.IAppOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Objects;

/**
 * 订单信息Controller
 * 
 * @author ruoyi
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/app/system/order")
public class AppApiOrderController extends BaseController
{
    @Autowired
    private IAppOrderService appOrderService;

    /**
     * 查询订单信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AppOrder appOrder)
    {
        startPage();
        if (Objects.nonNull(getLoginAppUser())) {
            appOrder.setUserId(getLoginAppUser().getUserId());
        }
        List<AppOrder> list = appOrderService.selectAppOrderList(appOrder);
        return getDataTable(list);
    }

    /**
     * 导出订单信息列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppOrder appOrder)
    {
        List<AppOrder> list = appOrderService.selectAppOrderList(appOrder);
        ExcelUtil<AppOrder> util = new ExcelUtil<AppOrder>(AppOrder.class);
        util.exportExcel(response, list, "订单信息数据");
    }

    /**
     * 获取订单信息详细信息
     */
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return success(appOrderService.selectAppOrderByOrderId(orderId));
    }

    /**
     * 新增订单信息
     */
    @PostMapping
    public AjaxResult add(@RequestBody AppOrder appOrder)
    {
        return toAjax(appOrderService.insertAppOrder(appOrder));
    }

    /**
     * 修改订单信息
     */
    @PutMapping
    public AjaxResult edit(@RequestBody AppOrder appOrder)
    {
        return toAjax(appOrderService.updateAppOrder(appOrder));
    }

    /**
     * 删除订单信息
     */
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(appOrderService.deleteAppOrderByOrderIds(orderIds));
    }
}
